package org.geektimes.configuration.microprofile.config.source.servlet;


import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.logging.Logger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @Author: menglinggang
 * @Date: 2021-03-24
 * @Time: 1:38 下午
 */
public class ServletConfigInitializer implements ServletContextListener {
    Logger logger = Logger.getLogger(ServletConfigInitializer.class.getSimpleName());

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ConfigProviderResolver instance = ConfigProviderResolver.instance();
        Config config = instance.getConfig();
        // 本地缓存
        ConfigUtils.init(config);
        // ServletContext
        ConfigUtils.init(servletContextEvent.getServletContext(), config);

        servletContextEvent.getServletContext().log("############## : config ServletConfigInitializer  contextInitialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        servletContextEvent.getServletContext().log("############## : config ServletConfigInitializer  contextDestroyed");
    }
}
